﻿using EMall.Domain;

namespace EMall.ProductService.Brands
{
    public class BrandManager : DomainService
    {
        private readonly IBrandRepository _brandRepository;
        public BrandManager(IBrandRepository brandRepository)
        {
            _brandRepository = brandRepository;
        }
        public async Task<string> CheckNameExistsAsync(string name)
        {
            var existing = await _brandRepository.GetByNameAsync(name);
            if (existing != null)
            {
                throw new Exception($"name {name} has already exists!");
            }
            return name;
        }
        public async Task<string> CheckNewNameExistsAsync(Brand entity, string name)
        {
            if (entity.Name == name)
            {
                return name;
            }
            return await CheckNameExistsAsync(name);
        }
    }
}
